﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DBMigrator.Core.DbObjects.Data.Update;
using Rhino.Mocks;
using StructureMap;
using Xunit;

namespace DBMigrator.Core.Tests.DbObjects.Data
{
    public class AdditionalSetTests
    {
        private readonly AdditionalSet additionalSet;
        private readonly ISetValue<object> setValue;

        public AdditionalSetTests()
        {
            additionalSet = new AdditionalSet();
            setValue = MockRepository.GenerateMock<ISetValue<object>>();
            ObjectFactory.Inject(setValue);
        }

        [Fact]
        public void AndSetShouldThrowIfColumnNameIsNull()
        {
            Assert.Throws<ArgumentNullException>(() => additionalSet.AndSet<object>(null));
        }

        [Fact]
        public void AndSetShouldThrowIfColumnNameIsBlank()
        {
            Assert.Throws<ArgumentNullException>(() => additionalSet.AndSet<object>(string.Empty));
        }

        [Fact]
        public void AndSetShouldSetColumnName()
        {
            var columnName = StringUtil.Random();
            additionalSet.AndSet<object>(columnName);
            Assert.Equal(columnName, additionalSet.ColumnName);
        }

        [Fact]
        public void AndSetShouldSetSetValue()
        {
            additionalSet.AndSet<object>("ColumnName");
            Assert.Equal(setValue, additionalSet.SetValue);
        }

        [Fact]
        public void AndSetShouldReturnSetValue()
        {
            Assert.Equal(setValue, additionalSet.AndSet<object>("ColumnName"));
        }
    }
}
